package com.igeek.entity;

import com.igeek.dao.UserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

public class Demo2 {

    public static void main(String[] args)throws Exception {

        //读取配置文件的输入流
        Reader reader = Resources.getResourceAsReader("mybatis.xml");
        //创建builder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        //构建sessionFactory
        SqlSessionFactory factory = builder.build(reader);
        //打开session
        SqlSession session = factory.openSession();

        //获取dao接口的实例
        UserDao userDao = session.getMapper(UserDao.class);
//        userDao.delete(6);

//        userDao.updatePwd(1, "123");

//        User user = userDao.findById(1);
//        System.out.println(user.getName());

//        User user = new User();
//        user.setId(1);
//        user.setPassword("222");
//        userDao.update(user);

        //增删改的持久化需要提交事务
        session.commit();

        session.close();
    }
}
